class Node:
    def __init__(self,val=0,next=None):
        self.val=val 
        self.next=next 

def solve(head):
    pre=None
    cur=head
    nxt=cur.next
    while cur:
        cur.next=pre
        pre=cur 
        cur=nxt 
        if nxt: nxt=nxt.next 
    return pre 

def build(lst):
    head=Node(lst[0])
    cur=head
    for i in range(1,len(lst)):
        cur.next=Node(lst[i])
        cur=cur.next 
    return head

def print_node(head):
    cur=head 
    while cur:
        print(cur.val)
        cur=cur.next


head=build([1,2,3,4,5])
head=solve(head)
print_node(head)



    

